package org.finalministry.gui.components.tree;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeCellRenderer;

public class IconTreeCellRenderer implements TreeCellRenderer {

	private JLabel label;

	public IconTreeCellRenderer() {
		label = new JLabel();
	}

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row,
			boolean hasFocus) {

		Object o = ((DefaultMutableTreeNode) value).getUserObject();

		if (value instanceof IFinalministryTreeNode == false && o.equals("Finalministry")) {
			label.setIcon(new ImageIcon("icons/earth15.png"));
			label.setText("" + value);
			return label;
		}

		if (value instanceof IFinalministryTreeNode == false) {
			label.setIcon(null);
			label.setText("" + value);
			return label;
		}

		IFinalministryTreeNode node = (IFinalministryTreeNode) value;

		label.setIcon(new ImageIcon(node.getIcon()));
		label.setText(node.getName());

		return label;
	}

}
